#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {
        sort(potions.begin(), potions.end());

        int n = spells.size();
        vector<int> nums;
        for (int i = 0; i < n; i++)
        {
            int m = potions.size();
            int left = 0, right = potions.size() - 1;
            while (left < right)
            {
                int mid = left + (right - left) / 2;
                if ((potions[mid] * (long long)spells[i]) >= success)
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if ((potions[right] * (long long)spells[i]) >= success)
            {
                nums.push_back(m - right);
            }
            else
            {
                nums.push_back(0);
            }
        }

        return nums;
    }
};

